//添加 修改
function addOrUpdGoodCategory(id, title) {
	var addOrUpdGoodCategoryForm = new Ext.form.FormPanel({
		id : 'addOrUpdGoodCategoryForm',
		frame : true,
		layout : "form",
		buttonAlign : 'center',
		labelWidth : 70,
		monitorValid : true,
		bodyBorder : false,
		fileUpload : true,// 上传文件设置为true
		reader : new Ext.data.JsonReader({
					success : 'success',
					root : 'data'
				}, [{
							name : "id"
						}, {
							name : "categoryName"
						}, {
							name : "categoryNamePingyin"
						}, {
							name : "categoryStatus"
						}, {
							name : "categoryOrder"
						}, {
							name : "createdName"
						}, {
							name : "createdDate"
						}, {
							name : "updatedName"
						}, {
							name : "updatedDate"
						}]),
						items : [{
			border : false,
			style : {
				"textAlign" : 'right'
			},
			layout : 'form',
			labelWidth : 40,
			items : [{
				layout : 'column',
				border : false,
				items : [{
					layout : 'form',
					border : false,
					labelWidth : 80,
					defaults : {
						labelStyle : "text-align:right"
					},
					items : [{
								id : 'cgFormId',
								xtype : 'hidden',
								name : 'id'
							},  {
								xtype : 'textfield',
								name : 'categoryName',
								anchor : '90%',
								fieldLabel : "<span style='color:#F00'>*</span>名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称",
								allowBlank : false,
								blankText : '名称不能为空'
							}, {
								
								xtype : 'textfield',
								name : 'categoryNamePingyin',
								anchor : '90%',
								fieldLabel : "<span style='color:#F00'>*</span>拼&nbsp;音&nbsp;名",
								allowBlank : false,
								blankText : '拼音名不能为空'
									
							}]
				}, {
					border : false,
					layout : 'form',
					labelWidth : 100,
					defaults : {
						labelStyle : "text-align:right"
					},
					items : [{
								name : "categoryOrder",
								xtype : "numberfield",
								anchor : '90%',
								fieldLabel : "<span style='color:#F00'>*</span>排&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;序",
								allowBlank : false,
								blankText : '排序不能为空',
								allowDecimals : false,// 禁用小数
								allowNegative : false
							}]
				}]
			}]
		}],
		buttons : [{
					id : 'addOrUpdCategoryCommit',
					text : '确定',
					formBind : true,
					handler : function() {
						insertOrUpdCategory();
					}
				}, {
					text : "取消",
					handler : function() {
						addOrUpdGoodCategoryWindow.close();
					}
				}]
	});
	var addOrUpdGoodCategoryWindow = new Ext.Window({
				id : 'addOrUpdGoodCategoryWindow',
				closeAction : 'close',
				title : title,
				closable : true,
				plain : true,
				draggable : false, // 不可拖动
				// resizable : false, // 不可调整
				modal : true,
				width : 450,
				height : 200,
				buttonAlign : 'center',
				autoDestroy : true,
				layout : 'fit',
				items : [addOrUpdGoodCategoryForm],
				listeners : {
					'show' : function() {
						selectid(id);
					},
					'beforeshow' : function() {
						addOrUpdGoodCategoryWindow.center();
					}
				}
			});
	return addOrUpdGoodCategoryWindow;
}

/**
 * 广告突变点击事件
 */
function clickHandler() {
	var imageShow_box = Ext.getCmp("vaForm_image");
	var subjectPicPath = imageShow_box.getEl().dom.src;
	window.open(subjectPicPath, '_blank');
}

/**
 * 添加或修改广告
 */
function insertOrUpdCategory() {
	var categoryForm = Ext.getCmp("addOrUpdGoodCategoryForm");
	var id = Ext.getCmp("cgFormId").getValue();
	if (categoryForm.getForm().isValid()) {
		Ext.Msg.confirm("提示框", "确认保存分类信息吗？", function(button) {
					if (button == "yes") {
						categoryForm.getForm().submit({
							url : __ctxPath
									+ '/goodCategoryManager/insertOrUpdateGoodCategory',
							waitTitle : "请稍候",
							waitMsg : "正在提交表单，请稍候......",
							failure : function(response, options) {
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "错误提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.ERROR
										});
							},
							success : function(response, options) {
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "提示信息",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.INFO
										});
								Ext.getCmp("addOrUpdGoodCategoryWindow").close();
								var gridPanel = Ext.getCmp("goodCategoryManagerGrid");
								if (typeof(gridPanel) != 'undefined') {
									gridPanel.store.reload();
								}
							}
						});

					}

				});
	}
}

/**
 * 查询广告信息
 * 
 * @param {}
 *            id
 */
function selectid(id) {
	if (id != null && id != "undefined") {
		var cgFormOrder = Ext.getCmp('cgFormOrder');
		Ext.getCmp("addOrUpdGoodCategoryForm").getForm().load({
			deferredRender : false,
			url : __ctxPath + "/goodCategoryManager/selectGoodCategoryById",
			params : {
				id : id
			},
			waitTitle : "请稍候",
			waitMsg : "正在载入数据...",
			root : "data",
			success : function(response, options) {
				var data = options.result.data;
				// 设置标题

			}

		});
	}
}
